# 类定义
class People:
    # 定义基本属性
    name = ''
    age = 0
    # 定义私有属性,类外部不能直接访问
    __weight = 0

    # 构造函数
    def __init__(self, name, age, weight):
        self.name = name
        self.age = age
        self.__weight = weight

    def hello(self):
        print(f'name:{self.name},age:{self.age},weight:{self.__weight}')


people = People('wangyue', 24, 140)
print('---------People--------')
people.hello()
# 获取私有属性
print(f'{people.name}的私有变量体重为：{people._People__weight}\n')


# 学生单继承People
class Student(People):
    grade = ''

    # 构造函数
    def __init__(self, name, age, weight, grade):
        # 调用父类的构造方法
        People.__init__(self, name, age, weight)
        self.grade = grade

    def hello(self):
        # weight要使用 '_类__私有属性' 的方式才能获取,因为是父类的私有属性，所以类为'People'
        print(f'name:{self.name},age:{self.age},weight:{self._People__weight},grade:{self.grade}\n')


student = Student('小王', 12, 80, '六年级')
print('---------People--------')
student._People__weight = 99  # 私有属性也可以更改
student.hello()


# 工作者类
class Worker:
    work = ''

    def __init__(self, name, work):
        self.name = name
        self.work = work

    def speak(self):
        print(f'name:{self.name},work:{self.work}')


# 多继承
class Programmer(Student, Worker):
    def __init__(self, name, age, weight, grade, work):
        Student.__init__(self, name, age, weight, grade)  # 构造学生
        Worker.__init__(self, name, work)  # 构造工作者

    def info(self):
        # 调用父类方法
        Student.hello(self)  # 父类.方法
        super().speak()  # super().方法


programmer = Programmer('张三', 35, 160, '本科', '程序员')
print('---------Programmer--------')
programmer.info()
programmer.speak()  # 调用父类的方法
